class Solution(object):
    def expressiveWords(self, s, words):
        c = []
        left = 0
        right = 0
        n = len(s)
        while right < n:
            if s[right] != s[left]:
                c.append([s[left], right - left])
                left = right
            right += 1
        c.append([s[left], right - left])
        t = len(c)
        out = 0
        for word in words:
            m = len(word)
            left = 0
            right = 0
            index = 0
            flag = True
            while right < m and index < t:
                if word[right] != word[left]:
                    if word[left] == c[index][0] and (
                            (right - left == c[index][1]) or (right - left < c[index][1] and c[index][1] >= 3)):
                        index += 1
                        left = right
                    else:
                        flag = False
                        break
                right += 1
            if flag:
                if index == t - 1 and word[left] == c[index][0] and (
                        (right - left == c[index][1]) or (right - left < c[index][1] and c[index][1] >= 3)):
                    out += 1
        return out


data = Solution()
s = "heeeelllooo"
words = ["hello", "hi", "helo"]
print(data.expressiveWords(s, words))
